//
//  AccountManagerViewController.m
//  WHB_logist
//
//  Created by 徐国庆 on 15/12/7.
//  Copyright (c) 2015年 turing. All rights reserved.
//

#import "AccountManagerViewController.h"
#import "ChangeHeaderPortraitViewController.h"
#import "changePassWordViewController.h"

@interface AccountManagerViewController ()<UITableViewDataSource, UITableViewDelegate>

@property(nonatomic, strong)UITableView *tableView;
@property(nonatomic, strong)User        *user;

@end

@implementation AccountManagerViewController

- (instancetype)initWithUser:(User *)user{
    self = [super init];
    if (self) {
        self.user = user;
    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.navtitle.text = @"账号管理";
    
    [self initWithView];
    
}

#pragma mark UITableVeiwDelegate
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 2;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *indentifer = @"accountManagerVC";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:indentifer];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:indentifer];
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    
    UILabel *bottomLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 43.5, kUIScreenWidth, 0.5)];
    bottomLabel.backgroundColor = [UIColor HexStrWithColor:@"cccccc"];
    [cell.contentView addSubview:bottomLabel];
    
    if (indexPath.row == 0) {
        cell.textLabel.text = @"注册手机号";
        cell.textLabel.font = [UIFont systemFontOfSize:17 weight:2];
        cell.detailTextLabel.text = self.user.telNum;//@"15146001603";
        cell.detailTextLabel.font = [UIFont systemFontOfSize:17 weight:2];
//        cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;
    } else if (indexPath.row == 2){
        cell.textLabel.text = @"注册手机号";
        cell.detailTextLabel.text = @"137434569382";
    } else if (indexPath.row == 1){
        cell.textLabel.text = @"登陆密码";
        
        // 密码
        UILabel *passWordLabel = [[UILabel alloc] initWithFrame:CGRectMake(kUIScreenWidth - 155, 0, 100, 44)];
        passWordLabel.text = @"******";
        passWordLabel.textAlignment = 2;
        [cell.contentView addSubview:passWordLabel];
        
        // 更换密图标
        UIImageView *changeImageView = [[UIImageView alloc] initWithFrame:CGRectMake(kUIScreenWidth - 50, 2, 32, 32)];
        changeImageView.image = [UIImage imageNamed:@"btn_icon_Mine_alter_normal"];
        [cell.contentView addSubview:changeImageView];
    }
    cell.textLabel.textColor = [UIColor HexStrWithColor:@"999999"];
    cell.textLabel.font = [UIFont systemFontOfSize:17 weight:2];
    cell.detailTextLabel.font = [UIFont systemFontOfSize:17];
    cell.detailTextLabel.textColor = [UIColor HexStrWithColor:@"333333"];
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.row == 2) {
        ChangeHeaderPortraitViewController *changeHeaderVC = [[ChangeHeaderPortraitViewController alloc] init];
        [self.navigationController pushViewController:changeHeaderVC animated:YES];
    } else if (indexPath.row == 1){
        changePassWordViewController *changePassWordVC = [[changePassWordViewController alloc] init];
        [self.navigationController pushViewController:changePassWordVC animated:YES];
    }
}

- (UIView *)footerView{
    
    UIView *bottomView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kUIScreenWidth, 40)];
    
    UIButton *footerButton = [UIButton buttonWithType:UIButtonTypeCustom];
    footerButton.frame = CGRectMake(50, 0, kUIScreenWidth - 100, 45);
    footerButton.layer.masksToBounds = YES;
    footerButton.layer.cornerRadius = 22.5;
    [footerButton setTitleColor:[UIColor HexStrWithColor:@"1b1b1b"] forState:UIControlStateNormal];
    [footerButton setTitle:@"退出登陆" forState:UIControlStateNormal];
    footerButton.backgroundColor = [UIColor HexStrWithColor:@"f8cc00"];
    [footerButton addTarget:self action:@selector(footerButtonAction:) forControlEvents:UIControlEventTouchDown];
    [bottomView addSubview:footerButton];
    return bottomView;
}

- (void)footerButtonAction:(UIButton *)button{
    // 删除用户数据信息
    [UtilsHelper deleArchiverFile:kUserPath];
}

- (void)initWithView{
    self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, -20, kUIScreenWidth, kUIScreenHeight) style:UITableViewStyleGrouped];
    self.tableView.dataSource = self;
    self.tableView.delegate = self;
    self.tableView.tableFooterView = [self footerView];
    self.tableView.backgroundColor = [UIColor HexStrWithColor:@"eeeeee"];
    [self.view addSubview:self.tableView];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
